package com.agiantii.ablog.handler.article.chain;

import com.agiantii.ablog.handler.article.chain.impl.ImageHandler;
import com.agiantii.ablog.handler.article.chain.impl.SensitiveWordHandler;
import com.agiantii.ablog.handler.article.chain.impl.TitleHandler;
import com.agiantii.ablog.handler.article.chain.impl.WordCountHandler;
import com.agiantii.ablog.pojo.dto.PostDTO;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class ContentHandlerChain {
    @Resource
    private WordCountHandler wordCountHandler;
    
    @Resource
    private SensitiveWordHandler sensitiveWordHandler;

    @Resource
    private ImageHandler imageHandler;

    @Resource
    TitleHandler titleHandler;

    private ContentHandler chain;
    
    @PostConstruct
    public void init() {
        // 构建责任链
        titleHandler.setNext(wordCountHandler);
        wordCountHandler.setNext(sensitiveWordHandler);
        sensitiveWordHandler.setNext(imageHandler);
        chain = titleHandler;
    }
    
    public void checkContent(PostDTO content) {
        chain.handle(content);
    }
} 